<?php

namespace ApplicationsModule\ExplorerModule;

use Nette\Object;
use Albireo\FileSystem\DataFile;

/**
 * FS Browser
 *
 * @author Kuku
 */
class ExplorerModel extends Object {

    public static function processDir(DataFile $df) {
        $dir = array();
        //\Nette\Debug::dump($df);
        foreach ($df->getData() as $oneFile) {
            $helper = ExplorerModel::processFileInfo($oneFile);
            $dir[$helper["Path"]] = $helper;
        }
        return $dir;
    }

    public static function processFileInfo(DataFile $oneFile) {
        $path = $oneFile->getUrl() . $oneFile->getName();
        $type = (strpos($oneFile->getMimetypeText(), 'dir') !== FALSE) ? 'dir' : substr($oneFile->getName(), strrpos($oneFile->getName(), '.') + 1);
        return array(
            'Path' => $path . ($type == 'dir' ? '/' : ''),
            'Filename' => $oneFile->getName(),
            'File Type' => $type,
            'Preview' => 'images/fileicons/' . $type . '.png',
            'Properties' => array(
                'Date Created' => null,
                'Date Modified' => null,
                'Height' => null,
                'Width' => null,
                'Size' => null
            ),
            'Error' => "",
            'Code' => 0
        );
    }

}
